home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Problem Negating an Unsigned Char
- Date: 4 Mar 1996 11:28:28 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4hfg8sINNhbq@keats.ugrad.cs.ubc.ca>
- References: <Dnnros.Lq.0.-s@hkusuc.hku.hk> <4he27sINNdel@keats.ugrad.cs.ubc.ca> <4he5f0$acv@solutions.solon.com>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4he5f0$acv@solutions.solon.com>,
- Peter Seebach <seebs@solutions.solon.com> wrote:
- >Close, but the cigar yet escapes you.
- >
- > if (a == (~b & ((1 << CHAR_BIT) - 1)))
-
- By the way, if you wanted to do this without the cast to unsigned char, why not
- use UCHAR_MAX? We know that this is a Mercenne number, 2^n-1, so you can just
- AND with that. Can UCHAR_MAX ever be something other than a dyadic power less
- one?
-
- if (a == (~b & UCHAR_MAX))
-
- That way you avoid the shifts.
-
- --
-
-